package com.sg.service.biz.component.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.component.req.ImplementTenReceivingFieldReqDto;
import com.sg.dto.biz.component.req.QueryConfItemMatchAnswerDetailComReqDto;
import com.sg.dto.biz.component.req.QueryWorkTaskCycleConfDetailComReqDto;
import com.sg.dto.biz.component.res.ImplementTenReceivingFieldRespDto;
import com.sg.dto.biz.component.res.QueryConfItemMatchAnswerDetailComRespDto;
import com.sg.dto.biz.component.res.QueryWorkTaskCycleConfDetailComRespDto;
import com.sg.service.base.component.MCustomFields3Service;
import com.sg.service.base.component.MOmsUnstructuredDataService;
import com.sg.service.biz.component.ConfSchemeService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class DashboardWorkTaskServiceImpl
        implements com.wicket.okrcomponent.biz.service.DashboardWorkTaskService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MOmsUnstructuredDataService mOmsUnstructuredDataService;
    @Resource
    private NbDashboardWorkTask nbDashboardWorkTask;
    @Resource
    private ConfSchemeService confSchemeService;
    @Resource
    private MCustomFields3Service mCustomFields3Service;

    /**
     * D2查询工作任务周期配置(公共)[8984]
     * gen by moon at 6/17/2024, 12:03:29 AM
     */
    @Trace(operationName = "D2查询工作任务周期配置(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryWorkTaskCycleConfDetailComRespDto queryWorkTaskCycleConfDetailCom(QueryWorkTaskCycleConfDetailComReqDto reqDto) {


        ImplementTenReceivingFieldRespDto receptionServiceRes_2 = null;
//步骤0: M2执行第十接收字段（特殊方法） - implementTenReceivingField
        //ModelCode: receptionService
        ImplementTenReceivingFieldRespDto receptionServiceRes = null;
        ImplementTenReceivingFieldReqDto receptionServiceReq = new ImplementTenReceivingFieldReqDto();
        if (reqDto != null) {
            receptionServiceReq.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1679249_1
        }

        /*M2接收入参字段[8782]  用于特殊方法接收上游入参。 */
        Assert.isNull(receptionServiceReq.getSpaceId(), "D2查询工作任务周期配置(公共)-M2接收入参字段-创建于空间ID不能为空", false);
        receptionServiceRes = nbDashboardWorkTask.implementTenReceivingField(receptionServiceReq);


//步骤1: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto.setResultAspObjType("TENANT_SPACE");//sourceId:1866998_1
        queryConfItemMatchAnswerDetailComReqDto.setConfItemCode("WORK_CYCLE_TYPE_CODE");//CUSTOM_CONVENTION//sourceId:1810304_1
        queryConfItemMatchAnswerDetailComReqDto.setIsPlatData("FALSE");//sourceId:1810313_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto.setResultAspObjId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1810306_1
        }

        /*D2查询工作周期周期类型配置答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getResultAspObjId(), "D2查询工作任务周期配置(公共)-D2查询工作周期周期类型配置答案-开通对象ID不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getResultAspObjType(), "D2查询工作任务周期配置(公共)-D2查询工作周期周期类型配置答案-开通对象类型编码不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfItemCode(), "D2查询工作任务周期配置(公共)-D2查询工作周期周期类型配置答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getIsPlatData(), "D2查询工作任务周期配置(公共)-D2查询工作周期周期类型配置答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto = confSchemeService.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto)/*vcase invoke isSameApp*/;


//步骤2: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto_2 = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto_1 = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto_1.setResultAspObjType("TENANT_SPACE");//sourceId:1866999_1
        queryConfItemMatchAnswerDetailComReqDto_1.setConfItemCode("UPDATE_CYCLE_TYPE_CODE");//CUSTOM_CONVENTION//sourceId:1810329_1
        queryConfItemMatchAnswerDetailComReqDto_1.setIsPlatData("FALSE");//sourceId:1810330_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto_1.setResultAspObjId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1810328_1
        }

        /*D2查空间状态大屏更新周期周期类型配置答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_1.getResultAspObjId(), "D2查询工作任务周期配置(公共)-D2查空间状态大屏更新周期周期类型配置答案-开通对象ID不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_1.getResultAspObjType(), "D2查询工作任务周期配置(公共)-D2查空间状态大屏更新周期周期类型配置答案-开通对象类型编码不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_1.getConfItemCode(), "D2查询工作任务周期配置(公共)-D2查空间状态大屏更新周期周期类型配置答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_1.getIsPlatData(), "D2查询工作任务周期配置(公共)-D2查空间状态大屏更新周期周期类型配置答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto_2 = confSchemeService.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto_1)/*vcase invoke isSameApp*/;


//步骤3: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto_4 = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto_2 = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto_2.setResultAspObjType("TENANT_SPACE");//sourceId:1867001_1
        queryConfItemMatchAnswerDetailComReqDto_2.setConfItemCode("IS_TENEMENT_CYCLE");//CUSTOM_CONVENTION//sourceId:1810325_1
        queryConfItemMatchAnswerDetailComReqDto_2.setIsPlatData("FALSE");//sourceId:1810326_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto_2.setResultAspObjId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1810324_1
        }

        /*D2查询空间工作周期是否租户周期类型配置答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_2.getResultAspObjId(), "D2查询工作任务周期配置(公共)-D2查询空间工作周期是否租户周期类型配置答案-开通对象ID不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_2.getResultAspObjType(), "D2查询工作任务周期配置(公共)-D2查询空间工作周期是否租户周期类型配置答案-开通对象类型编码不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_2.getConfItemCode(), "D2查询工作任务周期配置(公共)-D2查询空间工作周期是否租户周期类型配置答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_2.getIsPlatData(), "D2查询工作任务周期配置(公共)-D2查询空间工作周期是否租户周期类型配置答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto_4 = confSchemeService.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto_2)/*vcase invoke isSameApp*/;


//步骤4: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto_6 = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto_3 = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto_3.setResultAspObjType("TENANT_SPACE");//sourceId:1866996_1
        queryConfItemMatchAnswerDetailComReqDto_3.setConfOptionCode("WORK_CYCLE_START_TIME");//CUSTOM_CONVENTION//sourceId:1679026_1
        queryConfItemMatchAnswerDetailComReqDto_3.setConfItemCode("WORK_CYCLE_START_AND_END_TIME");//CUSTOM_CONVENTION//sourceId:1679025_1
        queryConfItemMatchAnswerDetailComReqDto_3.setIsPlatData("FALSE");//sourceId:1679027_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto_3.setResultAspObjId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1679024_1
        }

        /*D2状态大屏工作周期开始时间答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_3.getResultAspObjId(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期开始时间答案-开通对象ID不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_3.getResultAspObjType(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期开始时间答案-开通对象类型编码不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_3.getConfOptionCode(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期开始时间答案-选项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_3.getConfItemCode(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期开始时间答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_3.getIsPlatData(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期开始时间答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto_6 = confSchemeService.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto_3)/*vcase invoke isSameApp*/;


//步骤5: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto_8 = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto_4 = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto_4.setResultAspObjType("TENANT_SPACE");//sourceId:1866997_1
        queryConfItemMatchAnswerDetailComReqDto_4.setConfOptionCode("WORK_CYCLE_END_TIME");//CUSTOM_CONVENTION//sourceId:1679102_1
        queryConfItemMatchAnswerDetailComReqDto_4.setConfItemCode("WORK_CYCLE_START_AND_END_TIME");//CUSTOM_CONVENTION//sourceId:1679101_1
        queryConfItemMatchAnswerDetailComReqDto_4.setIsPlatData("FALSE");//sourceId:1679103_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto_4.setResultAspObjId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1679100_1
        }

        /*D2状态大屏工作周期结束时间配置答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_4.getResultAspObjId(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期结束时间配置答案-开通对象ID不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_4.getResultAspObjType(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期结束时间配置答案-开通对象类型编码不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_4.getConfOptionCode(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期结束时间配置答案-选项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_4.getConfItemCode(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期结束时间配置答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto_4.getIsPlatData(), "D2查询工作任务周期配置(公共)-D2状态大屏工作周期结束时间配置答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto_8 = confSchemeService.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto_4)/*vcase invoke isSameApp*/;


//步骤6: M2执行第十接收字段（特殊方法） - implementTenReceivingField
        //ModelCode: receptionService
        ImplementTenReceivingFieldRespDto receptionServiceRes_1 = null;
        if (queryConfItemMatchAnswerDetailComRespDto_2 != null) {
            ImplementTenReceivingFieldReqDto receptionServiceReq_1 = new ImplementTenReceivingFieldReqDto();
            if (queryConfItemMatchAnswerDetailComRespDto_2 != null) {
                receptionServiceReq_1.setUpdateCycleTypeCode(queryConfItemMatchAnswerDetailComRespDto_2.getEndValue());//SimpleFieldAssign//sourceId:1810334_1
            }
            if (queryConfItemMatchAnswerDetailComRespDto != null) {
                receptionServiceReq_1.setWorkCycleTypeCode(queryConfItemMatchAnswerDetailComRespDto.getEndValue());//SimpleFieldAssign//sourceId:1679407_1
            }
            if (queryConfItemMatchAnswerDetailComRespDto_4 != null) {
                receptionServiceReq_1.setIsTenementCycle(queryConfItemMatchAnswerDetailComRespDto_4.getEndValue());//SimpleFieldAssign//sourceId:1679408_1
            }
            if (queryConfItemMatchAnswerDetailComRespDto_6 != null) {
                receptionServiceReq_1.setWorkCycleStartTime(queryConfItemMatchAnswerDetailComRespDto_6.getEndValue() != null ? CommonFunctionHelper.str2Date(queryConfItemMatchAnswerDetailComRespDto_6.getEndValue()) : null);//SimpleFieldAssign//sourceId:1679409_1
            }
            if (queryConfItemMatchAnswerDetailComRespDto_8 != null) {
                receptionServiceReq_1.setWorkCycleEndTime(queryConfItemMatchAnswerDetailComRespDto_8.getEndValue() != null ? CommonFunctionHelper.str2Date(queryConfItemMatchAnswerDetailComRespDto_8.getEndValue()) : null);//SimpleFieldAssign//sourceId:1679410_1
            }

            /*M2接收工作周期配置出参[8782]  用于特殊方法接收上游入参。 */
            Assert.isNull(receptionServiceReq_1.getWorkCycleTypeCode(), "D2查询工作任务周期配置(公共)-M2接收工作周期配置出参-工作周期类型标识不能为空", false);
            Assert.isNull(receptionServiceReq_1.getIsTenementCycle(), "D2查询工作任务周期配置(公共)-M2接收工作周期配置出参-是否租户周期不能为空", false);
            receptionServiceRes_1 = nbDashboardWorkTask.implementTenReceivingField(receptionServiceReq_1);


            receptionServiceRes_2 = receptionServiceRes_1;
        }

        QueryWorkTaskCycleConfDetailComRespDto retData = new QueryWorkTaskCycleConfDetailComRespDto();
        if (receptionServiceRes_2 != null) {
            retData.setUpdateCycleTypeCode(receptionServiceRes_2.getUpdateCycleTypeCode());//SimpleFieldAssign//sourceId:1810336_1
            retData.setWorkCycleTypeCode(receptionServiceRes_2.getWorkCycleTypeCode());//SimpleFieldAssign//sourceId:1679429_1
            retData.setIsTenementCycle(receptionServiceRes_2.getIsTenementCycle());//SimpleFieldAssign//sourceId:1679430_1
            retData.setWorkCycleStartTime(receptionServiceRes_2.getWorkCycleStartTime());//SimpleFieldAssign//sourceId:1679431_1
            retData.setWorkCycleEndTime(receptionServiceRes_2.getWorkCycleEndTime());//SimpleFieldAssign//sourceId:1679432_1
        }


        return retData;
    }
    //
}
